﻿using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class test : MonoBehaviour
{

    // Use this for initialization
    void Start()
    {
        HttpModule.onPostEvent += OnPost;
    }

    private void OnPost(List<PostValue> obj)
    {
        try
        {
            for (int i = 0; i < obj.Count; i++)
            {
                if (obj[i].data == null || string.IsNullOrEmpty(obj[i].filename))
                    continue;
                System.IO.File.WriteAllBytes("./" + obj[i].filename, obj[i].data);

            }

        }
        catch (Exception ex)
        {

            Debug.LogError(ex);
        }

    }

    // Update is called once per frame
    void Update()
    {

        if (Input.GetKeyDown(KeyCode.Space))
        {
            WWWForm form = new WWWForm();
            //form.AddField("文件", "策划档案");
            form.AddField("test", "my file");
            form.AddBinaryData("ziduan", System.IO.File.ReadAllBytes(@"F:\HTTPServer\tex\arkit_1.jpg"), "arkit_1.jpg");

            HttpModule.PostRequest("http://192.168.40.93:5555/test", form, (str) => { Debug.Log(str); });
        }
    }
}
